/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package sessionbean;

import entitybean.Upload;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author Thien Nguyen
 */
@Stateless
@org.jboss.ejb3.annotation.RemoteBinding(jndiBinding = "UploadsJNDI")
@org.jboss.ejb3.annotation.LocalBinding(jndiBinding = "UploadsLocalJNDI")
public class UploadsSessionBean implements UploadsSessionBeanRemote, UploadsSessionBeanLocal {
    @PersistenceContext(unitName = "J2EE_ShareMusic-ejbPU")
    private EntityManager em;

    public void persist(Object object) {
        em.persist(object);
    }

    public List loadUpload() {
        String jpql = "SELECT a FROM Upload a";
        javax.persistence.Query query = em.createQuery(jpql);
        List list = query.getResultList();
        return list;
    }

    public List getUpload(int id) {
        String jpql = "SELECT a FROM Upload a WHERE a.uploadID =:id";
        javax.persistence.Query query = em.createQuery(jpql);
        query.setParameter("id", id);
        List list = query.getResultList();
        return list;
    }

    public boolean deleteUpload(int id) {
        Upload upload = em.find(Upload.class, id);
        if(upload != null) {
            em.remove(upload);
            return true;
        }
        return false;
    }


}
